from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
from time import sleep
from appium.webdriver.common.mobileby import MobileBy
from faker import Faker
import pytest
import allure
@allure.feature("小豆苗APP")
class TestLogin:
    faker = Faker(locale='zh_cn')
    phone = str(faker.phone_number())
    @pytest.fixture(scope='function',autouse=True)
    def setup_teardown(self):
        cap_dict = {
            "platformName": "Android",
            "platformVersion": "7.1.2",
            "deviceName": "x1q",
            "appPackage": "com.threegene.doctor",
            "appActivity": ".module.splash.SplashActivity"
        }
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", cap_dict)
        self.driver.implicitly_wait(15)
        yield
        self.driver.quit()
    @allure.story("手机验证码登录")
    def test_login(self):
        sleep(3)
        TouchAction(self.driver).tap(x=462, y=1119).perform()
        # 使用轻扫进行滑动页面：第一次
        sleep(2)
        self.driver.swipe(861, 1364, 46, 1373)
        # 使用轻扫进行滑动页面：第二次
        sleep(2)
        self.driver.swipe(861, 1364, 46, 1373)
        # 点击立即体验
        self.driver.find_element(MobileBy.ID, "com.threegene.doctor:id/submit_btn").click()
        # 点击已阅读
        self.driver.find_element(MobileBy.CLASS_NAME, "android.widget.CompoundButton").click()
        # 点击手机号登录
        self.driver.find_element(MobileBy.ID, "com.threegene.doctor:id/tv_phone_login").click()
        # 输入手机号
        self. driver.find_element(MobileBy.ID, "com.threegene.doctor:id/edit_phone_number").send_keys(self.phone)
        # 点击获取验证码
        self.driver.find_element(MobileBy.ID, "com.threegene.doctor:id/tv_send_code").click()
        # 断言
        text = self.driver.find_element(MobileBy.ID, "com.threegene.doctor:id/sms_send_hint").text
        assert self.phone[-4:] in text